package com.common.service;

import com.common.dao.adminDao;
import com.common.entity.admin;
import com.common.utils.jwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class service {
    @Autowired
    private  adminDao dao;

    public admin Login(String username,String password)
    {
        admin a = dao.findByUsernameAndPassword(username,password);
       if(a!=null)
       {
           a.setToken(jwtUtil.createJwt());
       }
       return a;
    }
    public List<admin> getAll(){
        return dao.findAll();
    }
    public admin update(admin a)
    {
        return dao.save(a);
    }
    public boolean check(String token)
    {
        return jwtUtil.parse(token);

    }
    public void deleteOne(Integer id)
    {
        dao.deleteById(id);
    }
    public void deleteMany(List<Integer> ids)
    {
        dao.deleteAllByIdInBatch(ids);
    }
}
